package com.apobates.jforum2.troll.forum.mapper;

import com.apobates.jforum2.troll.forum.entity.BoardConfig;
import com.apobates.jforum2.troll.forum.stub.vo.BoardConfigVo;
import com.apobates.jforum2.troll.utils.core.api.OptionalEntityTransformMapper;
import java.util.Optional;
import java.util.function.Function;

/**
 *
 * @author xiaofanku
 */
public class BoardConfigVoMapperEntity implements OptionalEntityTransformMapper<BoardConfig, BoardConfigVo>{
    @Override
    public Optional<BoardConfigVo> transform(Optional<BoardConfig> entity) {
        return entity.map(ins->{
            return mapper().apply(ins);
        });
    }

    public static Function<BoardConfig, BoardConfigVo> mapper(){
        return boardConfig -> {
            BoardConfigVo bcv = new BoardConfigVo();
            //配置文件ID
            bcv.setId(boardConfig.getId());
            //版块ID
            bcv.setBoard(boardConfig.getBoardId());
            //true(1)表示可读可写,false(0)表示只读
            bcv.setReadWrite(boardConfig.isReadWrite());
            // 写
            // 作者可编辑内容的时间有效期(分钟).-1表示不限制
            bcv.setEditMinute(boardConfig.getEditMinute());
            // 同一会员不间断的发贴的数量
            bcv.setWriteMinInterrupt(boardConfig.getWriteMinInterrupt());
            // 积分需求
            bcv.setWriteMinScore(boardConfig.getWriteMinScore());
            // 会员组需求
            bcv.setWriteLowMemberGroup(boardConfig.getWriteLowMemberGroup().getSymbol());
            // 会员角色需求
            bcv.setWriteLowMemberRole(boardConfig.getWriteLowMemberRole().getSymbol());
            // 会员等级需求
            bcv.setWriteLowMemberLevel(boardConfig.getWriteLowMemberLevel());
            // 读
            // 积分需求
            bcv.setReadMinScore(boardConfig.getReadMinScore());
            // 会员组需求
            bcv.setReadLowMemberGroup(boardConfig.getReadLowMemberGroup().getSymbol());
            // 会员角色需求
            bcv.setReadLowMemberRole(boardConfig.getReadLowMemberRole().getSymbol());
            // 会员等级需求
            bcv.setReadLowMemberLevel(boardConfig.getReadLowMemberLevel());
            //不分读写操作设置
            // ip地址过滤,true(1)过滤,false(0)不过滤
            bcv.setIpFilter(boardConfig.isIpFilter());
            return bcv;
        };
    }
}